

package com.scalar.chiptrack.sales.forms;


import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.commons.Address;
import com.scalar.chiptrack.sales.Customer;

/**
 * Form bean for the customer_setup page.  This form has the following fields,
 * with default values in square brackets:
 * <ul>
 * <li><b>action</b> - The maintenance action we are performing (Create. Modify & Save).
 * </ul>
 *
 * @author Kesava Kumar Achanala
 * @version $Revision: 1.2 $ $Date: 2010/04/18 09:48:53 $
 */




public final class CustomerForm extends ChipTrackActionForm  {


    // --------------------------------------------------- Instance Variables


	private String action = null;

	private Customer customer = new Customer();
        private int customerId = -1;


    // ----------------------------------------------------------- Properties



    /**
     * Get Customer
     *
     * @return Customer
     */
    public Customer getCustomer()
    {
	return customer;
    }

    /**
     * Set the Customer
     *
     * @param Customer
     */
    public void setCustomer(Customer customer)
    {
 	this.customer = customer;
    }

   /**
    * Get action
    *
    * @return action
    */
   public String getAction()
   {
	   return action;
   }

   /**
    * Set the action
    *
    * @param action
    */
   public void setAction(String action)
   {
 	this.action = action;
   }
 //Added by Sarada on 4th July 2003
   public int getCustomerId()
   {
       return customerId;
   }    
       
    public void setCustomerId(int customerId)
   {
       this.customerId = customerId;
   }    
       


    // --------------------------------------------------------- Public Methods


    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        //This is simple hack.. as the shipping locations are becoming 0 everytime you click addshipping location
        ArrayList list = null;
        ArrayList billingLocaions = null;
        if(customer != null) {
            list =  this.customer.getShippingLocations();
            billingLocaions = this.customer.getBillingLocations();
        }
        this.customer = null;
        customer = new Customer();
        customer.setShippingLocations(list);
        customer.setBillingLocations(billingLocaions);
        // Added by Veeru on 1st Oct 2004 to persist the value receive shipping alerts when form is reset
        customer.getShippingAddress().setReceiveShipAlert("off");

        for (int i = 0; i < list.size(); i++) {
            Address address = (Address) list.get(i);
            address.setReceiveShipAlert("off");
        }
        // End of Added by Veeru
    }


    /**
     * Validate the properties that have been set from this HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {

        ActionErrors errors = new ActionErrors();

        //if ((vendorName == null) || (vendorName.length() < 1))
        //    errors.add("Vendor", new ActionError("error.vendor name.required"));
        return errors;

    }


}
